package com.shiliao.app.activity.interlocution.presenter;

import android.text.TextUtils;

import com.shiliao.app.activity.interlocution.entity.InterlocutionEntity;
import com.shiliao.app.activity.interlocution.service.InterLocutionService;
import com.shiliao.app.activity.interlocution.service.impl.InterLocutionImpl;
import com.shiliao.app.activity.interlocution.view.InterlocutionView;
import com.shiliao.app.utils.YMServerUtil;
import com.yimei.framework.mvp.presenter.IBasePresenter;
import com.yimei.framework.network.ICallBack;
import com.yimei.framework.util.LogUtil;
import com.yimei.framework.util.ParseHelper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by yinzhiqiang on 2017/9/12.
 */

public class InterLocutionPresenter extends IBasePresenter<InterLocutionService> {
    private InterLocutionService interLocutionService;
    private InterlocutionView interlocutionView;

    public InterLocutionPresenter(InterlocutionView interlocutionView) {
        this.interlocutionView = interlocutionView;
        interLocutionService = new InterLocutionImpl();
    }


    public void request(String question, String userId) {
        super.loadData();
        HashMap map = new HashMap();
        if (!TextUtils.isEmpty(userId)) {
            map.put("user_id", userId);
        }
        if (!TextUtils.isEmpty(question)) {
            map.put("question", question);
        }
        interLocutionService.request(YMServerUtil.ACTION_SUBMIT_QUESTION, map, new ICallBack() {
            @Override
            public void onSuccess(int statusCode, Object result) {
                LogUtil.e("yzq", result.toString());
                List<InterlocutionEntity> list = ParseHelper.getModelList(result.toString(), "question_array",
                        InterlocutionEntity.class);
                LogUtil.e("yzq", "...." + list.size());
                interlocutionView.sumbitQuestion(list);
            }

            @Override
            public void onFail(int statusCode, Object result) {

            }
        });
    }

    public void requestSumbitNewQuestion(String question, String userId) {
        Map map = new HashMap();
        if (!TextUtils.isEmpty(userId)) {
            map.put("user_id", userId);
        }
        if (!TextUtils.isEmpty(question)) {
            map.put("question", question);
        }
        interLocutionService.requestSumbitNewQuestion(YMServerUtil.ACTION_SUBMIT_NEW_QUESTION, map, new ICallBack() {
            @Override
            public void onSuccess(int statusCode, Object result) {
                LogUtil.e("yzq", "...." + result.toString());
                interlocutionView.hideLoadingView();
                interlocutionView.sumbitSuccess();
            }

            @Override
            public void onFail(int statusCode, Object result) {

            }
        });

    }

}
